package com.ruoyi.alarm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.alarm.domain.AlarmPush;
import com.ruoyi.alarm.service.IAlarmPushService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 告警推送Controller
 * 
 * @author yepanpan
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/alarm/push")
public class AlarmPushController extends BaseController
{
    @Autowired
    private IAlarmPushService alarmPushService;

    /**
     * 查询告警推送列表
     */
    @PreAuthorize("@ss.hasPermi('alarm:push:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlarmPush alarmPush)
    {
        startPage();
        List<AlarmPush> list = alarmPushService.selectAlarmPushList(alarmPush);
        return getDataTable(list);
    }

    /**
     * 导出告警推送列表
     */
    @PreAuthorize("@ss.hasPermi('alarm:push:export')")
    @Log(title = "告警推送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlarmPush alarmPush)
    {
        List<AlarmPush> list = alarmPushService.selectAlarmPushList(alarmPush);
        ExcelUtil<AlarmPush> util = new ExcelUtil<AlarmPush>(AlarmPush.class);
        util.exportExcel(response, list, "告警推送数据");
    }


    /**
     * 获取告警推送详细信息
     */
    @PreAuthorize("@ss.hasPermi('alarm:push:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(alarmPushService.selectAlarmPushById(id));
    }

    /**
     * 新增告警推送
     */
    @PreAuthorize("@ss.hasPermi('alarm:push:add')")
    @Log(title = "告警推送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AlarmPush alarmPush)
    {
        return toAjax(alarmPushService.insertAlarmPush(alarmPush));
    }

    /**
     * 修改告警推送
     */
    @PreAuthorize("@ss.hasPermi('alarm:push:edit')")
    @Log(title = "告警推送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody AlarmPush alarmPush)
    {
        return toAjax(alarmPushService.updateAlarmPush(alarmPush));
    }

    /**
     * 删除告警推送
     */
    @PreAuthorize("@ss.hasPermi('alarm:push:remove')")
    @Log(title = "告警推送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(alarmPushService.deleteAlarmPushByIds(ids));
    }
}
